require File.join(File.dirname(__FILE__), 'firefox-extension.rb')

desc "Build the extension, i.e. zip up the content of src/ as a .xpi and move it to the the build directory"
task :build do
  config = YAML.load_file(File.join(FirefoxExtension::EXTENSION_CONFIG_DIRECTORY, 'extension.yml'))
  
  `rm -rf #{FirefoxExtension::EXTENSION_BUILD_DIRECTORY}`
  `mkdir #{FirefoxExtension::EXTENSION_BUILD_DIRECTORY}`
  
  FirefoxExtension::InstallManifest.generate(config, FirefoxExtension::EXTENSION_SRC_DIRECTORY)
  filename = "#{config[:extension][:filename]}-without-update-url-#{config[:extension][:version]}.xpi"
  `cd #{FirefoxExtension::EXTENSION_SRC_DIRECTORY} && zip -r #{filename} *`
  `mv #{File.join(FirefoxExtension::EXTENSION_SRC_DIRECTORY, filename)} #{FirefoxExtension::EXTENSION_BUILD_DIRECTORY}`
  
  FirefoxExtension::InstallManifest.generate(config, FirefoxExtension::EXTENSION_SRC_DIRECTORY, include_update_url = true)
  filename = "#{config[:extension][:filename]}-#{config[:extension][:version]}.xpi"
  `cd #{FirefoxExtension::EXTENSION_SRC_DIRECTORY} && zip -r #{filename} *`
  `mv #{File.join(FirefoxExtension::EXTENSION_SRC_DIRECTORY, filename)} #{FirefoxExtension::EXTENSION_BUILD_DIRECTORY}`
  
  FirefoxExtension::UpdateManifest.generate(config, FirefoxExtension::EXTENSION_BUILD_DIRECTORY)
  filename = "#{config[:extension][:filename]}-update.rdf"
  `mv #{File.join(FirefoxExtension::EXTENSION_BUILD_DIRECTORY, 'update.rdf')} #{File.join(FirefoxExtension::EXTENSION_BUILD_DIRECTORY, filename)}`
end